﻿namespace Hanoi
{
    internal class Program
    {
        /// <summary>
        /// Hanoi小游戏
        /// </summary>
        public static void Move(int piles, char x, char y, char z)
        {
            //只有一层时，直接将其从x移动到z
            if (piles == 1)
            {
                Console.WriteLine($"第{piles}个盘子{x}-->{y}");
            }
            else
            {
                ///上面的piles-1个盘从x经过z移到y
                Move(piles - 1, x, z, y);
                ///最下面的从x移到y
                Console.WriteLine($"第{piles}个圆盘{x}-->{y}");
                //上面的piles-1个盘从z经过y到x
                Move(piles - 1, z, y, x);
            }
        }
        static void Main(string[] args)
        {
            int piles = 0;
            Console.Write("请输入汉诺塔的层数");
            piles = int.Parse(Console.ReadLine());
            if (piles > 0)
            {
                //调用函数Move
                Move(piles, 'x', 'y', 'z');
                Console.ReadKey();
                return;
            }
        }
    }
}
